<?php

namespace App\Admin\Controllers;

use App\Admin\Actions\Grid\OrderGoodsAction;
use App\Admin\Repositories\WxShopOrderGoods;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class WxShopOrderGoodsController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new WxShopOrderGoods(), function (Grid $grid) {
            $grid->model()->orderBy('id', 'desc');
            $grid->column('id')->sortable();
            $grid->column('pic')->image('', 80);
            $grid->column('name');
            $grid->column('product')->limit(20);
            $grid->column('vip_price');
            $grid->column('price');
            $grid->column('quantity');
            $grid->column('order_id')->label('primary');
            $grid->column('goods_id')->label('primary');
            $grid->column('product_id')->label('primary');
            $grid->column('type')->using([0 => '正常', 1 => '补发', 2 => '赠送'])->label([
                0 => 'green',
                1 => 'blue',
                2 => 'orange2'
            ]);
            $grid->column('state')->using([0 => '正常', 1 => '退款中', 2 => '退货退款', 3 => '已退款', 4 => '异常'])->label([
                0 => 'green',
                1 => 'red',
                2 => 'red',
                3 => 'red',
                5 => 'primary',
            ]);
            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });

            $grid->actions(function (Grid\Displayers\Actions $actions) {
                $actions->append((new OrderGoodsAction())->setKey($this->id));
            });

            $grid->disableCreateButton();
//            $grid->disableActions();
            // 禁用编辑按钮
            $grid->disableEditButton();
            $grid->disableDeleteButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new WxShopOrderGoods(), function (Show $show) {
            $show->field('id');
            $show->field('pic');
            $show->field('name');
            $show->field('product');
            $show->field('vip_price');
            $show->field('price');
            $show->field('quantity');
            $show->field('order_id');
            $show->field('goods_id');
            $show->field('product_id');
            $show->field('type');
            $show->field('state');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new WxShopOrderGoods(), function (Form $form) {
            $form->display('id');
            $form->text('pic');
            $form->text('name');
            $form->text('product');
            $form->text('vip_price');
            $form->text('price');
            $form->text('quantity');
            $form->text('order_id');
            $form->text('goods_id');
            $form->text('product_id');
            $form->text('type');
            $form->text('state');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
